package pl.edu.agh.gt.ga;

public class Individual implements Comparable<Individual> {

	private static int idGenerator = 0;
	static int deathCounterInit;
	
	/**
	 * XXX private fields
	 */
	public int id;
	public Genotype genotype;
	public float fitness;
	public int	deathCounter;
	public IndividualListener listener;
	
	public Individual (Genotype gens) {
		id = idGenerator++;
		genotype = gens;
		deathCounter = deathCounterInit;
	}
	
	@Override
	public String toString() {
		return "ID="+id+"\t[FITNESS="+fitness+", gens: "+genotype+"]";
	}

	@Override
	public int compareTo(Individual o) {
		if(this.fitness < o.fitness)
			return -1;
		if(this.fitness > o.fitness)
			return 1;
		return 0;
	}
	
	@Override
	public boolean equals(Object obj) {
		if( obj instanceof Individual) {
			if( genotype.equals(((Individual)obj).genotype) ) {
				assert (this.fitness == ((Individual)obj).fitness);
				return true;
			}
			return false;
		} else 
			return super.equals(obj);
	}
}
